
function addPresenceValidation(elementID) {
	var js = document.createElement('script');
	var headID = document.getElementsByTagName('head')[0];     
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.text = "var f1 = new LiveValidation( '"+elementID+"', {validMessage:' '});f1.add( Validate.Presence, { failureMessage: ' ' } );";
 
	headID.appendChild(newScript);
}

function addClosedQuestionValidation(){
	
	var newdiv = document.createElement('div');	
	newdiv.id='saf';
	
	
	
}

function addNumericalityValidation(elementID) {
	var js = document.createElement('script');
	var headID = document.getElementsByTagName('head')[0];     
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.text = "var f1 = new LiveValidation( '"+elementID+"', {validMessage:'  '});f1.add( Validate.Presence, { failureMessage: 'Podaj liczbe!' } );"+
	"f1.add( Validate.Numericality , { minimum: 0,tooLowMessage:'Liczba dodatnia!',notANumberMessage: 'Podaj liczbę!',notAnIntegerMessage:'Liczba całkowita!',onlyInteger:true  } ); " ;
	headID.appendChild(newScript);

}


function disableCQValidation(obj){
	
	
	var x=obj.parentNode.childNodes[3].childNodes[3].id;
	removeValidation(x);
	x=obj.parentNode.childNodes[7].childNodes[3].id;
	removeValidation(x);
	x=obj.parentNode.childNodes[9].childNodes[3].id;
	removeValidation(x);
	x=obj.parentNode.childNodes[11].childNodes[1].id;
	removeValidation(x)	;
	
}


function disableOQValidation(obj){
	
	var x=obj.parentNode.childNodes[5].childNodes[3].id;
	removeValidation(x)	;
	
}



function removeValidation(elementID) {
	var headID = document.getElementsByTagName('head')[0];     
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.text = "var f1 = new LiveValidation( '"+elementID+"', {validMessage:'  '});"+
	"f1.disable(); " ;
	headID.appendChild(newScript);	
}
function checkboxlimit(checkgroup, min,max){
	var checkgroup=checkgroup
	var limit=limit
	for (var i=0; i<checkgroup.length; i++){
		checkgroup[i].onclick=function(){
		var checkedcount=0
		for (var i=0; i<checkgroup.length; i++)
			checkedcount+=(checkgroup[i].checked)? 1 : 0
		if (checkedcount>max){
				var answer = confirm("Maksymalna liczba odpowiedzi to:"+max+" ankieta z nieprawidłową liczbą odp nie będzie mogła być wysłana.\nKontynuować?")
				if (!answer){	
					this.checked=false	
				}
			}
		if (checkedcount<min && !this.checked ){
			var answer = confirm("Minimalna liczba odpowiedzi to:"+min+" ankieta z nieprawidłową liczbą odp nie będzie mogła być wysłana.\nKontynuować?")
				if (!answer){	
					this.checked=false	
				}

			}
		}
	}
}

function if_student(){
	
	var selectvar = document.getElementById('user_positionID');		
    var dropdownIndex = selectvar.selectedIndex;
    var value = selectvar.options[dropdownIndex].text;	
    if(value=='Student'){
    	document.getElementById('user_study_period').enable()
	}
	else{
		document.getElementById('user_study_period').disable()
	}

	
}

function if_student2(){
	
	var selectvar = document.getElementById('user_positionID');		
    var dropdownIndex = selectvar.selectedIndex;
    var value = selectvar.options[dropdownIndex].text;	
    if(value=='Student'){
    	document.getElementById('period_check').enable()
	}
	else{
		document.getElementById('user_study_period').disable()
		document.getElementById('period_check').disable()
	}

	
}

function switchActivation(source,target){
	if(document.getElementById(source).checked)
		document.getElementById(target).enable()
	else
		document.getElementById(target).disable()
}
function switchStudent(source,selectPosition,selectPeriod,checkForPeriod){
	if(document.getElementById(source).checked){
		document.getElementById(selectPosition).enable()
		document.getElementById(selectPeriod).disable()
		if_student2()
	}
	else{
		document.getElementById(selectPeriod).disable()
		document.getElementById(selectPosition).disable()
	document.getElementById(checkForPeriod).checked=false	
		document.getElementById(checkForPeriod).disable()	
	}
}	